import articleApi, { IArticle } from "@/apis/articleApi"

import { defineStore} from "pinia"
export default defineStore('bokInfo',{
    state:()=>{
        return {
            bokInfo:[] as any,
            pageNum:1 as number,
            totalPages:1 as number,
            //当天的博客
            currentDayBoks:[] as any,
            queryBokList:[] as any,
           
        }
    },
    actions:{ //点击分页之后存储当前页的用户博客信息
       async ClickStoreBokInfo(pageNum:number){
          this.bokInfo=   (await articleApi.article(pageNum)).data;
 
        this.pageNum=this.bokInfo?.currentPage;
        this.totalPages=this.bokInfo?.page_count;
        return this.bokInfo;
       },

       //获取当天的博客信息，根据三个信息来排名(comments goods views)
    async   getCurrentDayBokRanking(){
        this.currentDayBoks= (await articleApi.allArticle()).data as IArticle[]
        

    }, 

    //获取当前的被点击的博客,发送请求
   async getCurrentPageByQuery(queryBid:any){
      
   this.queryBokList= (await   articleApi.getbokBybid(queryBid)).data
 
    },

 
     
    },
    
   
    persist:{
        
         key:'bokinfo',
         storage:sessionStorage
    }
})